from collections import Counter

# 找出一个序列中出现次数最多的元素
words_1 = ['a','a','b','b','b','c']
words_2 = ['a','d','e','e','e','f']

def demo_1():
    # Counter对象可以接受任意的由可hashable元素构成的序列对象
    # 在底层实现上，一个Counter对象就是一个字典，将元素映射到它出现的次数上
    counter_1 = Counter(words_1)
    # 出现频率最高的2个单词
    top_two = counter_1.most_common(2)
    print(top_two)
    print(counter_1['a'])
    print(counter_1['b'])
    print(counter_1['c'])

    counter_2 = Counter(words_2)
    # 并集
    counter_3 = counter_1 + counter_2
    # 差集
    counter_4 = counter_1 - counter_2
    # 交集
    counter_5 = counter_1 & counter_2
    print(counter_3)
    print(counter_4)
    print(counter_5)


if __name__ == '__main__':
    demo_1()